<?php
declare(strict_types=1);

namespace App\Article;

use App\Controller;
use Field\SysArticleConst;
use Field\SysCateConst;

// hook controller_users_index_use.php

/**
 * @title   新闻动态
 * @auth    true
 * @rank    10
 */
class Index extends Controller
{
    // hook controller_users_index_public_start.php

    // hook controller_users_index_public_end.php
    protected string $name = '';
    /**
     * @title    首页
     * @rank    99
     */
    public function action_Index()
    {
        $catePinyin = '/'.$this->request->param('name', 'news');
        !empty($this->name) && $catePinyin = $this->name;
        $page = $this->request->param('page', 1);
        $title = [];
        $cond = [];
        $path = '/';

        if (!empty($catePinyin) && empty($this->SysCate->DataPinyin[$catePinyin])) {
            $this->response('0301', [], '分类不存在', '/', 301);
        }

        $DataCate = $this->SysCate->DataKey[$this->SysCate->DataPinyin[$catePinyin]];
        $path =  $catePinyin;

        if (!empty($this->SysCate->DataSon[$DataCate['CateID']])) {
            $CateIDs = $this->SysCate->DataSon[$DataCate['CateID']];
            $CateIDs[] = $DataCate['CateID'];
            $cond[SysArticleConst::CateID] = $CateIDs;
        } else {
            $cond[SysArticleConst::CateID] = $DataCate['CateID'];
        }
        $title[] = $DataCate['Name'];
        $orderby = [SysArticleConst::ArticleID => -1];
        $List = $this->SysArticle->GetList($cond, $orderby, $page, 20);
        $page > 1 && $title[] = '第' . $page . '页';
        $List['total'] = 10000;
        $pagination = pagination("{$path}/{page}", $List['total'], $page, 20);
        return $this->View(get_defined_vars(),'@Index.Index');
    }



    /**
     * @title   详情页
     * @rank    99
     */
    public function action_Detail()
    {
        $catePinyin = '/'.$this->request->param('name', 'news');
        !empty($this->name) && $catePinyin = $this->name;
        $title = [];
        if (!empty($catePinyin) && empty($this->SysCate->DataPinyin[$catePinyin])) {
            $this->response('0301', [], '分类不存在', '/', 301);
        }
        $ArticleID = $this->request->param('ArticleID', 0);
        empty($ArticleID) && $this->response('0301', [], '内容不存在', $catePinyin, 301);
        $DataCate = $this->SysCate->DataKey[$this->SysCate->DataPinyin[$catePinyin]];
        return $this->View(get_defined_vars(),'@Index.Detail');
    }

    /**
     * @title    首页
     * @rank    99
     */
    public function action_Promotion()
    {
        $this->name='/promotion';
        return $this->action_Index();
    }
    /**
     * @title   详情页
     * @rank    99
     */
    public function action_Promotiondetail()
    {

        return $this->action_Detail();
    }

    /**
     * @title   测试
     * @rank    99
     */
    public function action_Test(){
        $this->response('0001', [], '分类不存在123');
    }

    // hook controller_users_index_end.php
}

?>